﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary.DAO;
using mprsc.Reports;

namespace mprsc
{
    public partial class Main : Form
    {
        TblPhoneBranDAO phoneBrand = new TblPhoneBranDAO(Global.CONNECTION_STRING);
        TblBookingDAO orderDAO = new TblBookingDAO(Global.CONNECTION_STRING);
        public Main()
        {
            InitializeComponent();   
        }

        private void searchJobToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FindJob findJob = new FindJob();
            findJob.Show();
        }

        private void addNewCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewCustomer addnewCus = new NewCustomer();
            addnewCus.Show();
        }

        private void loginToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            Login login = new Login();
            login.ShowDialog();
            if (Global.isloged == true)
            {
                searchJobToolStripMenuItem.Enabled = true;
                listJobNonwarantyToolStripMenuItem.Enabled = true;
                listJobWarrantyToolStripMenuItem.Enabled = true;
                addNewBookingToolStripMenuItem.Enabled = true;
                addNewCustomerToolStripMenuItem.Enabled = true;
                customerListToolStripMenuItem.Enabled = true;
                actionListToolStripMenuItem.Enabled = true;
                newPerchaseToolStripMenuItem.Enabled = true;
                productToolStripMenuItem.Enabled = true;
                loanPhoneToolStripMenuItem.Enabled = true;
                phoneBrandToolStripMenuItem.Enabled = true;
                JobListNonWarranty jobListNonWarranty = new JobListNonWarranty();
                jobListNonWarranty.Show();
            }
            else
            {
                searchJobToolStripMenuItem.Enabled = false;
                listJobNonwarantyToolStripMenuItem.Enabled = false;
                listJobWarrantyToolStripMenuItem.Enabled = false;
                addNewBookingToolStripMenuItem.Enabled = false;
                addNewCustomerToolStripMenuItem.Enabled = false;
                customerListToolStripMenuItem.Enabled = false;
                actionListToolStripMenuItem.Enabled = false;
                newPerchaseToolStripMenuItem.Enabled = false;
                productToolStripMenuItem.Enabled = false;
                loanPhoneToolStripMenuItem.Enabled = false;
                phoneBrandToolStripMenuItem.Enabled = false;    
            }
        }

        private void Main_Load(object sender, EventArgs e)
        {
            // form ra giữa màn hình
            this.CenterToScreen();
            this.WindowState = FormWindowState.Maximized;
            if (Global.isloged == true)
            {
                searchJobToolStripMenuItem.Enabled = true;
                listJobNonwarantyToolStripMenuItem.Enabled = true;
                listJobWarrantyToolStripMenuItem.Enabled = true;
                addNewBookingToolStripMenuItem.Enabled = true;
                addNewCustomerToolStripMenuItem.Enabled = true;
                customerListToolStripMenuItem.Enabled = true;
                actionListToolStripMenuItem.Enabled = true;
                newPerchaseToolStripMenuItem.Enabled = true;
                productToolStripMenuItem.Enabled = true;
                loanPhoneToolStripMenuItem.Enabled = true;
                phoneBrandToolStripMenuItem.Enabled = true;
            }
            else
            {
                searchJobToolStripMenuItem.Enabled = false;
                listJobNonwarantyToolStripMenuItem.Enabled = false;
                listJobWarrantyToolStripMenuItem.Enabled = false;
                addNewBookingToolStripMenuItem.Enabled = false;
                addNewCustomerToolStripMenuItem.Enabled = false;
                customerListToolStripMenuItem.Enabled = false;
                actionListToolStripMenuItem.Enabled = false;
                newPerchaseToolStripMenuItem.Enabled = false;
                productToolStripMenuItem.Enabled = false;
                loanPhoneToolStripMenuItem.Enabled = false;
                phoneBrandToolStripMenuItem.Enabled = false;
            }
        }

        private void customerListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SearchCustomer searchCus = new SearchCustomer();
            searchCus.Show();
        }

        private void addNewBookingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewBooking newBooking = new NewBooking();
            newBooking.Show();
        }

        private void productToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //NewProduct newProduct = new NewProduct();
            //newProduct.Show();
            ListProduct listPro = new ListProduct();
            listPro.Show();
        }

        private void phoneBrandToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PhoneBrand_Model phoneBrand_Model = new PhoneBrand_Model();
            phoneBrand_Model.Show();
        }

        private void loanPhoneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoanPhone loanphone = new LoanPhone();
            loanphone.Show();
        }

        private void newPerchaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Purchase purchase = new Purchase();
            purchase.Show();
        }

        private void listJobNonwarantyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            JobListNonWarranty jobNonWa = new JobListNonWarranty();
            jobNonWa.Show();
        }

        private void listJobWarrantyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            JobListWarranty jobWarranty = new JobListWarranty();
            jobWarranty.Show();

        }

        private void actionListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListAction listAction = new ListAction();
            listAction.Show();
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            var data = phoneBrand.GetAll();
            var reportHienthi = new CrystalReport3();
            reportHienthi.SetDataSource(data);
            ReportViewer rp = new ReportViewer();
            rp.SetReport(reportHienthi);
            rp.Show(this);
        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            DataTable data = orderDAO.GetBook_ByIDCustomer(80);

            var report = new CrystalReport6();

            report.SetDataSource(data);

            var reportViewer = new ReportViewer();

            reportViewer.SetReport(report);

            reportViewer.Show(this);
        }

        private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
